package com.zlq.cn.api;

import lombok.Data;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@Data
public class ResponseException extends RuntimeException {
    public static void resultApiError(String msg) {
        throw new ResponseException(ApiCodeEnum.API_ERROR.getCode(), msg);
    }

    public static void resultError(String code, String msg) {
        throw new ResponseException(code, msg);
    }

    public static void resultError(ApiCodeEnum apiCodeEnum) {
        throw new ResponseException(apiCodeEnum.getCode(), apiCodeEnum.getMsg());
    }

    public static void resultError(String code, String msg, Object data) {
        throw new ResponseException(code, msg, data);
    }

    private String code;
    private String msg;
    private Object data;

    public ResponseException(String msg) {
        super(msg);
        this.msg = msg;
    }

    public ResponseException(String code, String msg) {
        super(msg);
        this.msg = msg;
        this.code = code;
    }

    public ResponseException(String code, String msg, Object data) {
        super(msg);
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

}
